package com.iplus.ydkf.ehome.module.video;

import android.annotation.TargetApi;
import android.os.Build;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

import com.iplus.ydkf.ehome.R;
import com.iplus.ydkf.ehome.module.base.BaseFragment;

import butterknife.Bind;

/**
 * Created by liuhaitian on 16/5/8.
 */
public class VideoFragment extends BaseFragment {
    @Bind(R.id.webview)
    WebView webView;
    private static VideoFragment fragment;

    public static VideoFragment getInstance() {
        if (fragment == null)
            fragment = new VideoFragment();
        return fragment;
    }

    @Override
    public int bindLayout() {
        return R.layout.fragment_video;
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    @Override
    public void initView(View view) {
        webView.setWebChromeClient(new WebChromeClient());
        webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
        webView.loadData(
                "<!DOCTYPE html>\n" +
                        "<html lang=\"en\">\n" +
                        "<head>\n" +
                        "    <meta charset=\"UTF-8\">\n" +
                        "    <title>移动端页面（H5、微信）Demo</title>\n" +
                        "</head>\n" +
                        "<body>\n" +
                        "    <video src=\"http://vshare.ys7.com:80/openlive/600842422_1_1.m3u8?ticket=REdSbGd1ZWd2ODR2bGVWMTRKVHRqYzg3Qi9oWldjcFE5Z25lTWUwd0xGcz0kMSQyMDE3MDYxNDAwMDA0NyQxNDY1NzU4MDMyMDAwJDE0OTczNjk2MDAwMDAkMSQkJA==\"  /*此处填写购买获取到的m3u8地址 必填*/\n" +
                        "           controls=\"controls\" width=\"100%\" height=\"100%\" controls autoplay>\n" +
                        "    </video>\n" +
                        "</body>\n" +
                        "</html>", "text/html", "UTF-8");
    }

    @Override
    public void onPause() {
        super.onPause();
        webView.onPause();
    }

    @Override
    public void initData(View view) {
    }

    @Override
    public void onResume() {
        super.onResume();
        webView.onResume();
    }


    @Override
    public String getFragmentName() {
        return "监控";
    }

    @Override
    protected void lazyLoad() {

    }
}
